package 尊享面试.滑动窗口;

public class a487最大连续1的个数 {
    static class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
            int len = nums.length;
            int i = 0;
            int j = 0;
            int cnt = 0;
            int ans = 0;
            int lastZero = 0;
            while (j < len) {
                if (nums[j] == 0) {
                    cnt++;
                    if (cnt > 1) {
                        i = lastZero + 1;
                    }
                    lastZero = j;
                }
                ans = Math.max(ans, j - i + 1);
                j++;
            }
            return ans;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] num = {1,0,1,1,0};
        System.out.println(solution.findMaxConsecutiveOnes(num));
    }
}
